﻿<div ms-controller="tempview">

    <div class="sui-form form-inline" style="padding-top:5px;">
        分类：
        <select class="input-medium input-xfat" ms-duplex="Type1">
            <option value="">请选择分类</option>
            <option ms-repeat-el="TypeList1" ms-attr-value="el.ID">{{el.TypeName}}</option>
        </select>
        <select class="input-medium input-xfat" ms-duplex="Type2">
            <option value="">请选择分类</option>
            <option ms-repeat-el="TypeList2" ms-attr-value="el.ID">{{el.TypeName}}</option>
        </select>
        上下架状态：
        <select class="input-medium input-xfat" ms-duplex="IsShelf">
            <option value="">所有</option>
            <option value="1" >上架</option>
            <option value="0" >下架</option>
        </select>
        推荐
        <select class="input-medium input-xfat" ms-duplex="ToTop">
            <option value="">所有</option>
            <option value="1">推荐</option>
            <option value="0">无推荐</option>
        </select>
        <input type="text" ms-duplex="searchkey" placeholder="关键字搜索" class="input-large input-xfat" />
        <a class="sui-btn btn-large btn-primary" style="margin-left:10px;" ms-click="GetLIST()">查询</a>
        <a style="margin-left:10px;" class="sui-btn btn-large btn-success" ms-click="ADD('')" >添加</a>
    </div>

    <div>
        <table class="sui-table table-primary table-zebra">
            <thead>
                <tr>
                    <th>分类</th>
                    <th>标题</th>
                    <th>图片</th>
                    <th>价格</th>
                    <th style="width:70px">创建时间</th>
                    <th style="width:40px">状态</th>
                    <th style="width:150px">操作</th>
                </tr>
            </thead>
            <tbody>
                <tr ms-repeat-el="ListData">
                    <td>{{el.TypeName1}}/{{el.TypeName2}}</td>
                    <td>{{el.Title}}</td>
                    <td><img ms-src="ComFunJS.FilePath(el.ImgUrl,'/50/50')" /></td>
                    <td>销售价:{{el.Price1}},成本价:{{el.Price2}},可用存款:{{el.Point}}</td>
                    <td>{{el.CRTime|date('yyyy-MM-dd')}}</td>
                    <td>
                        <span class='sui-text-success' ms-visible="el.IsShelf==1">上架</span>
                        <span class='sui-text-danger' ms-visible="el.IsShelf!=1">下架</span><br />
                        <span class='sui-text-warning' ms-visible="el.ToTop==1">推荐</span>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="sui-btn btn-bordered btn-warning" ms-click="SetShelf(el)">{{el.IsShelf==1?'下架':'上架'}}</a>
                        <a href="javascript:void(0);" class="sui-btn btn-bordered btn-info" ms-click="SetToTop(el)">{{el.ToTop==1?'取消推荐':'推荐'}}</a>
                        <a href="javascript:void(0);" class="sui-btn btn-bordered btn-success" ms-click="ADD(el)" style="margin-top:3px;">编辑</a>
                        <a href="javascript:void(0);" class="sui-btn btn-bordered btn-danger" ms-click="DEL(el)" style="margin-top:3px;">删除</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

   

</div>
<script type="text/javascript">
    var tempmodel = avalon.define({
        $id: "tempview",
        Type1: "",
        Type2: "",
        TypeList1: [],
        TypeList2: [],
        IsShelf: "",
        ToTop:"",
        Init: function () {
            $.getJSON("/adapi/base/cate/list/1/0", function (r) {
                tempmodel.TypeList1 = r.result;
            })
            tempmodel.GetLIST();
        },
        GetLIST: function () {
            model.page.pageindex = 1;
            model.ListData.clear();
            $.getJSON("/adapi/product/list", { pageindex: model.page.pageindex, pagesize: model.page.pagesize, "searchkey": model.searchkey, "Type1": tempmodel.Type1, "Type2": tempmodel.Type2, "IsShelf": tempmodel.IsShelf, "ToTop": tempmodel.ToTop }, function (r) {
                if (r.error == "") {
                    model.ListData = r.result;
                    model.total = r.total;

                    $("#pageDiv").pagination({  //分页容器
                        styleClass: ['sui-pagination'],  //分页样式
                        //showCtrl: false,
                        displayPage: 6,
                        itemsCount: r.total,
                        pageSize: model.page.pagesize,
                        onSelect: function (num) {
                            model.page.pageindex = num;
                            $.getJSON("/adapi/product/list", { pageindex: model.page.pageindex, pagesize: model.page.pagesize, "searchkey": model.searchkey, "Type1": tempmodel.Type1, "Type2": tempmodel.Type2, "IsShelf": tempmodel.IsShelf, "ToTop": tempmodel.ToTop }, function (r) {
                                model.ListData.clear();
                                model.ListData = r.result;
                            })
                        }
                    })

                    $('#pageDiv').pagination('updateItemsCount', r.total, 1);
                }
            })
        }


    })

    tempmodel.$watch("Type1", function () {
        tempmodel.TypeList2.clear();
        tempmodel.Type2 = "";
        if (tempmodel.Type1) {
            $.getJSON("/adapi/base/cate/list/1/" + tempmodel.Type1, function (r) {
                tempmodel.TypeList2 = r.result;
            })
        }

    })


</script>

